package com.shenda.device.handler.handlers;

import org.springframework.stereotype.Component;

import com.shenda.api.entity.Gyro;
import com.shenda.consumer.event.GyroEvent;
import com.shenda.consumer.event.GyroEvent.GyroEventType;
import com.shenda.device.Constants;
import com.shenda.device.Device;
import com.shenda.device.message.RespMsg;
import com.shenda.device.message.RespMsg_Flush;
import com.swak.eventbus.EventBus;
import com.swak.utils.time.DateTimes;

/**
 * 配置设备
 * 
 * @author lifeng
 */
@Component
public class FlushHandler extends AbstractHandler {

	@Override
	protected boolean supportCmds(RespMsg resp) {
		return resp instanceof RespMsg_Flush;
	}

	/**
	 * 设置到设备中
	 */
	@Override
	protected void doInnerHandle(RespMsg resp) {
		Device device = resp.getDevice();
		if (Constants.SUCCESS.equals(resp.getContent())) {
			Gyro gyro = new Gyro();
			gyro.setId(device.getMac());
			gyro.setLastFlushTime(DateTimes.getFormatNow("yyyyMMddHHmmss"));
			EventBus.me().post(new GyroEvent().setGyro(gyro).setType(GyroEventType.檫除));
		}
	}
}